<template>
  <div class="dashboard-editor-container">
    <div>
      <el-card>
        <el-form :model="ruleForm" style="margin-top:10px;" size="mini" label-position="top" ref="ruleForm">
          <el-row :gutter="10">
            <el-col :lg="4" :md="6">
              <el-form-item label="批次号" prop="BATCHNO">
              <!-- <el-select v-model="ruleForm.BATCHNO" size="mini" clearable placeholder="请选择批次号">
                <el-option v-for="item in batchOption" :key="item.BATCHNO" :label="item.BATCHNO"
                  :value="item.BATCHNO"></el-option>
              </el-select> -->
               <el-input size="mini" v-model="ruleForm.BATCHNO" placeholder="请输入批次号"></el-input>
            </el-form-item>
            </el-col>
            <el-col :lg="4" :md="6">
              <el-form-item label="客户等级" prop="CUSTOMLEVEL">
                <el-select v-model="ruleForm.CUSTOMLEVEL" size="mini" clearable placeholder="请选择采集方式">
                  <el-option v-for="item in levelOption" :value="item.key" :key="item.key" :label="item.label">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :lg="4" :md="6">
              <el-form-item label="渠道" prop="CHANNELTYPE">
                <el-select v-model="ruleForm.CHANNELTYPE" size="mini" clearable placeholder="请选择渠道">
                  <el-option v-for="item in channelOption" :key="item.FIELDKEY" :label="item.FIELDVALUE"
                    :value="item.FIELDKEY"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :lg="8" :md="12" class="searchBtnMarginTop"  :offset="4">
              <el-button type="primary" icon="el-icon-search" :loading="loading" size="mini" @click="queryData">查询
              </el-button>
              <el-button type='warning' size='mini' icon='el-icon-refresh' @click="clearForm('ruleForm')">重置</el-button>
              <!-- <el-button type='success' size='mini' icon='el-icon-s-tools' @click="openUpdate">触发自动抽样</el-button> -->
            </el-col>
            </el-row>
            <el-row :gutter="10">
            <el-col :lg="4" :md="6">
              <el-form-item label="业务类型" prop="BUSINESSTYPE">
                <el-select v-model="ruleForm.BUSINESSTYPE" size="mini" clearable placeholder="请选择业务类型">
                  <el-option v-for="item in typeOption" :value="item.key" :key="item.key" :label="item.label">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :lg="4" :md="6">
              <el-form-item label="多媒体类型" prop="MEDIATYPE">
                <el-select v-model="ruleForm.MEDIATYPE" size="mini" clearable placeholder="请选择多媒体类型">
                  <el-option v-for="item in mediaOption" :key="item.FIELDKEY" :label="item.FIELDVALUE"
                    :value="item.FIELDKEY"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :lg="4" :md="6">
              <el-form-item label="坐席级别" prop="AGENTLEVEL">
                <el-select v-model="ruleForm.AGENTLEVEL" size="mini" clearable placeholder="请选择坐席级别">
                  <el-option v-for="item in agentOption" :value="item.key" :key="item.key" :label="item.label">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            
          </el-row>
        </el-form>
      </el-card>
    </div>
    <el-row style="margin-top:20px">
      <el-col>
        <el-card>
          <el-button type="success" @click="saveSampleData" size="mini" :disabled="currentRow.length<1">保存为抽样数据
          </el-button>
          <el-table :data="tableData" @selection-change="handleCurrentChange" class="tableMarginTop" border
            highlight-current-row ref="tableData">
            <el-table-column type="selection" width="40px"></el-table-column>
            <el-table-column prop='COLLECTSERNO' label='采集流水号' width="100"></el-table-column>
            <el-table-column prop='BATCHNO' label='采集批次号' width="100" align="center"></el-table-column>
            <el-table-column prop='BATCHDATE' label='采集日期' width="100" align="center"></el-table-column>
            <el-table-column prop='SESSIONID' label='会话ID' align="center" width="100"></el-table-column>
            <el-table-column prop='MEDIATYPE' label='多媒体类型' align="center" width="100"></el-table-column>
            <el-table-column prop='CHANNELTYPE' label='渠道类型' align="center"></el-table-column>
            <el-table-column prop='BEGINTIME' label='会话开始时间' align="center" width="110"></el-table-column>
            <el-table-column prop='ENDTIME' label='会话结束时间' align="center" width="110"></el-table-column>
            <el-table-column prop='SESSIONTIME' label='会话持续时长' align="center" width="110"></el-table-column>
            <el-table-column prop='BRNO' label='机构号' align="center"></el-table-column>
            <el-table-column prop='BUSINESSTYPE' label='业务类型' align="center"></el-table-column>
            <el-table-column prop='COLLECTFLAG' label='采集方式' align="center"></el-table-column>
            <el-table-column prop='FILEPATH' label='音视频文件路径' align="center" width="120"></el-table-column>
            <el-table-column prop='SAMPLEFLAG' label='抽样标识' align="center"></el-table-column>
            <el-table-column prop='TASKID' label='任务号' align="center"></el-table-column>
            <el-table-column prop='CUSTOMER' label='客户姓名' align="center"></el-table-column>
            <el-table-column prop='CUSTOMLEVEL' label='客户等级' align="center"></el-table-column>
            <el-table-column prop='TELNUMBER' label='电话号码' align="center" width="110"></el-table-column>
            <el-table-column prop='CUSTOMIDTYPE' label='证件类型' align="center"></el-table-column>
            <el-table-column prop='CUSTOMIDNO' label='客户证件号' align="center" width="120"></el-table-column>
            <el-table-column prop='CALLTYPE' label='呼叫类型' align="center"></el-table-column>
            <el-table-column prop='AREA' label='运营地区' align="center"></el-table-column>
            <el-table-column prop='AGENTID' label='坐席ID' align="center"></el-table-column>
            <el-table-column prop='AGENTNAME' label='坐席姓名' align="center"></el-table-column>
            <el-table-column prop='AGENTLEVEL' label='坐席级别' align="center"></el-table-column>
            <el-table-column prop='EXTNO' label='分机号' align="center"></el-table-column>
            <el-table-column prop='TEAM' label='班组' align="center"></el-table-column>
            <el-table-column prop='SKILL' label='技能组' align="center"></el-table-column>
            <el-table-column prop='SATISFIED' label='满意度' align="center"></el-table-column>
          </el-table>
          <div style="text-align:right;margin-top:20px;" v-show="this.tableData">
            <el-pagination :current-page="currentPage" background @size-change="handleSizeChange"
              :page-sizes="[10,25,50,100]" :page-size="pageSize" layout="total,sizes, prev, pager, next, jumper"
              :total="tableTotal" @current-change="changePage"></el-pagination>
          </div>
        </el-card>
      </el-col>
    </el-row>
    <!-- <el-dialog width="50%" title="触发自动抽样" :close-on-click-modal="false" :visible.sync="updateIsShow" append-to-body
      @close="closeDialog">
      <el-row>
        <el-form :model="updateForm" size="mini" label-width="100px" ref="updateForm">
          <el-col :span="24">
            <el-form-item label="批次" prop="BATCHNO">
              <el-select v-model="updateForm.BATCHNO" size="mini" clearable placeholder="请选择批次">
                <el-option v-for="item in updateOption" :value="item.BATCHNO" :key="item.BATCHNO" :label="item.BATCHNO+'-'+item.BATCHDATE">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item>
              <el-button type="primary" @click="submitForm('updateForm')">触发</el-button>
              <el-button @click="updateIsShow = false">取消</el-button>
            </el-form-item>
          </el-col>
        </el-form>
      </el-row>
    </el-dialog> -->
  </div>
</template>

<script>
  // 发送接口
  import getGlobalParams from "@/common/utils/getGlobalParams";
  import request from "@/common/utils/requestQC";
  import dataQuery from "@/message/QCManage/sampleManage/dataManualSample/dataManualSampleQuery";
  import dataSave from "@/message/QCManage/sampleManage/saveSampleData/saveSampleData";
  import triggerSample from "@/message/QCManage/sampleManage/triggerSample/triggerSample";
  import toolBox from "@/common/utils/toolBox";
  import dictionary from '@/message/wfm/baseData/dictionaryManage/dictionaryQuery'
  import requestWFM from "@/common/utils/requestWFM";

  //批量上传
  export default {
    name: '',
    data() {
      return {

        updateForm: {
          BATCHNO: '',
        },
        updateIsShow: false,
        currentRow: [],
        levelOption: [{
            key: '001',
            label: '非VIP'
          },
          {
            key: '002',
            label: 'VIP黄金级'
          },
          {
            key: '003',
            label: 'VIP铂金级'
          },
          {
            key: '004',
            label: 'VIP钻石级'
          },
        ],
        channelOption: [],
        typeOption: [{
            key: '0',
            label: '账务类'
          },
          {
            key: '1',
            label: '签约类'
          },
          {
            key: '2',
            label: '信息维护类'
          },
          {
            key: '3',
            label: '账户类'
          },
          {
            key: '4',
            label: '理财类'
          },
        ],
        updateOption:[],
        mediaOption: [],
        agentOption: [{
            key: '001',
            label: '一星'
          },
          {
            key: '002',
            label: '二星'
          },
          {
            key: '003',
            label: '三星'
          },
          {
            key: '004',
            label: '四星'
          },
          {
            key: '005',
            label: '五星'
          },
        ],
        tableTotal: 0,
        pageSize: undefined,
        currentPage: 1, //表格当前页
        tableData: [],
        ruleForm: {
          BATCHNO: '',//批次号
          CUSTOMLEVEL: '', //客户等级
          CHANNELTYPE: '', //渠道
          BUSINESSTYPE: '', //业务类型
          MEDIATYPE: '', //多媒体类型
          AGENTLEVEL: '', //坐席级别
        },
        loading: false,
      }
    },
    computed: {},
    created() {
      this.pageSize = getGlobalParams.get("PageSize");
    },
    mounted() {
      this.queryData()
      this.mediaQuery()
      this.channelQuery()
      // this.batchQuery()
    },
    watch: {},
    methods: {
       submitForm(formName) {
        this.$refs[formName].validate(async (valid) => {
          if (valid) {
            let date = ''
            this.updateOption.forEach(item=>{
              if(item.BATCHNO == this.updateForm.BATCHNO){
                date = item.BATCHDATE
              }
            })
            let resBody = new triggerSample()
            resBody.data.COLLECTFLAG = '1'
            resBody.data.BATCHNO = this.updateForm.BATCHNO
            resBody.data.BATCHDATE = date
            let response = await request(resBody);
            if (response.SYS_HEAD.ReturnCode == "000000") {
              this.$message({
                type: 'success',
                message: '触发成功!'
              });
              this.updateIsShow = false
              this.queryData()
            } else {
              this.$message({
                type: "error",
                message: "请求失败，错误码:" + response.SYS_HEAD.ReturnCode + "，错误信息：" + response.SYS_HEAD
                  .ReturnMessage
              })
            }
          } else {
            console.log('error submit!!');
            return false;
          }
        });
      },
      closeDialog() {
        if (this.$refs['updateForm'] != undefined) {
          this.$refs['updateForm'].clearValidate();
          this.$refs['updateForm'].resetFields();
        }
      },
      // // 打开触发自动抽样
      // openUpdate() {
      //   let data = JSON.parse(JSON.stringify(this.tableData))
      //   const obj = {}
      //   const newObjArr = data.reduce((prev, curr) => {
      //     obj[curr.BATCHNO] ? true : obj[curr.BATCHNO] = true && prev.push({
      //       BATCHNO: curr.BATCHNO,
      //       BATCHDATE: curr.BATCHDATE
      //     });
      //     return prev
      //   }, [])
      //   this.updateOption = newObjArr
      //   this.updateIsShow = true
      // },
      // 查询业务渠道
      async channelQuery() {
        let resBody = new dictionary();
        resBody.data.FIELDCODE = 'CHANNELTYPE'
        resBody.data.CurrPage = 1
        resBody.data.PageRowNum = 100
        let response = await requestWFM(resBody);
        if (response.SYS_HEAD.ReturnCode == "000000") {
          this.channelOption = response.BODY.FIEDATA;
        } else {
          this.$message({
            type: "error",
            message: "请求失败，错误码:" + response.SYS_HEAD.ReturnCode + "，错误信息：" + response.SYS_HEAD.ReturnMessage
          })
        }
      },
      // 查询多媒体类型
      async mediaQuery() {
        let resBody = new dictionary();
        resBody.data.FIELDCODE = 'MULMEDIATYPE'
        resBody.data.CurrPage = 1
        resBody.data.PageRowNum = 100
        let response = await requestWFM(resBody);
        if (response.SYS_HEAD.ReturnCode == "000000") {
          this.mediaOption = response.BODY.FIEDATA;
        } else {
          this.$message({
            type: "error",
            message: "请求失败，错误码:" + response.SYS_HEAD.ReturnCode + "，错误信息：" + response.SYS_HEAD.ReturnMessage
          })
        }
      },
      // 查询抽样数据
      async queryData() {
        let resBody = new dataQuery()
        resBody.data.BATCHNO = this.ruleForm.BATCHNO
        resBody.data.CUSTOMLEVEL = this.ruleForm.CUSTOMLEVEL
        resBody.data.CHANNELTYPE = this.ruleForm.CHANNELTYPE
        resBody.data.BUSINESSTYPE = this.ruleForm.BUSINESSTYPE
        resBody.data.MEDIATYPE = this.ruleForm.MEDIATYPE
        resBody.data.AGENTLEVEL = this.ruleForm.AGENTLEVEL
        resBody.data.CurrPage = this.currentPage + ''
        resBody.data.PageRowNum = this.pageSize + ''
        let response = await request(resBody);
        if (response.SYS_HEAD.ReturnCode == "000000") {
          this.tableData = response.BODY.RSPSTRUCT
          this.tableTotal = response.BODY.TotalRowNum
        } else {
          this.$message({
            type: "error",
            message: "请求失败，错误码:" + response.SYS_HEAD.ReturnCode + "，错误信息：" + response.SYS_HEAD.ReturnMessage
          })
        }
      },
      // 抽样数据存储
      async saveSampleData() {
        let date = new Date()
        let year = date.getFullYear()
        let month = date.getMonth() + 1
        let day = date.getDate()
        month = month < 10 ? '0' + month : month
        day = day < 10 ? '0' + day : day
        let nowDate = year + '' + month + '' + day;
        let arr = []
        this.currentRow.forEach(item => {
          arr.push(item.COLLECTSERNO)
        })
        let resBody = new dataSave()
        resBody.data.COLLECTSERNO = arr.join(',')
        resBody.data.COLLECTDATE = nowDate
        resBody.data.COLLECTFLAG = '1' //1-手动
        resBody.data.SAMPLER = this.$store.getters.UserNum;
        let response = await request(resBody);
        if (response.SYS_HEAD.ReturnCode == "000000") {
          this.$message({
            type: 'success',
            message: '保存成功！'
          })
          this.queryData()
        } else {
          this.$message({
            type: "error",
            message: "请求失败，错误码:" + response.SYS_HEAD.ReturnCode + "，错误信息：" + response.SYS_HEAD.ReturnMessage
          })
        }
      },
      changePage(val) {
        this.currentPage = val;
        this.queryData()
      },
      handleSizeChange(val) {
        this.pageSize = val
        this.queryData()
      },
      handleCurrentChange(val) {
        this.currentRow = val;
      },
      // 重置查询条件
      clearForm(item) {
        // 重置表格
        this.$refs["" + item].resetFields();
      },
    }
  }

</script>

<style rel="stylesheet/scss" lang="scss" scoped>

</style>
